
class AIAssistant:
    def __init__(self, id, name, type, version, online, score):
        self.id = id
        self.name = name
        self.type = type
        self.version = version
        self.online = online
        self.score = score

    def __str__(self):
        status = "在线" if self.online else "离线"
        return f"ID:{self.id}, 名称:{self.name}, 类型:{self.type}, 版本:{self.version}, 状态:{status}, 能力评分:{self.score}"

assistants = []  # 存储AI助手的列表

def show_menu():
    print("\n========== AI助手管理器 ==========")
    print("1. 查看所有AI助手")
    print("2. 根据ID查询助手详情")
    print("3. 添加新的AI助手")
    print("4. 修改助手信息")
    print("5. 删除AI助手")
    print("6. 启动AI助手")
    print("7. 停止AI助手")
    print("8. 显示系统统计信息")
    print("0. 退出系统")
    print("===================================")

def find_by_id(aid):
    for a in assistants:
        if a.id == aid:
            return a
    return None

while True:
    show_menu()
    choice = input("请选择操作: ")

    if choice == "1":
        if not assistants:
            print("暂无AI助手。")
        else:
            print("所有AI助手列表：")
            for a in assistants:
                print(a)

    elif choice == "2":
        aid = input("请输入ID: ")
        a = find_by_id(aid)
        if a:
            print("查询结果:", a)
        else:
            print("未找到该ID。")

    elif choice == "3":
        aid = input("请输入ID: ")
        name = input("请输入名称: ")
        type_ = input("请输入类型: ")
        version = input("请输入版本号: ")
        online = input("是否在线(1是/0否): ") == "1"
        score = int(input("请输入能力评分(0-100): "))
        assistants.append(AIAssistant(aid, name, type_, version, online, score))
        print(f"✅ 助手【{name}】添加成功！")

    elif choice == "4":
        aid = input("请输入要修改的ID: ")
        a = find_by_id(aid)
        if a:
            field = input("要修改的属性(name/type/version/online/score): ")
            value = input("新的值: ")
            if field == "online":
                a.online = (value == "1")
            elif field == "score":
                a.score = int(value)
            else:
                setattr(a, field, value)
            print("✅ 修改成功！")
        else:
            print("未找到该ID。")

    elif choice == "5":
        aid = input("请输入要删除的ID: ")
        a = find_by_id(aid)
        if a:
            assistants.remove(a)
            print(f"✅ 助手【{a.name}】已删除。")
        else:
            print("未找到该ID。")

    elif choice == "6":
        aid = input("请输入要启动的ID: ")
        a = find_by_id(aid)
        if a:
            a.online = True
            print(f"✅ 助手【{a.name}】已启动。")
        else:
            print("未找到该ID。")

    elif choice == "7":
        aid = input("请输入要停止的ID: ")
        a = find_by_id(aid)
        if a:
            a.online = False
            print(f"✅ 助手【{a.name}】已停止。")
        else:
            print("未找到该ID。")

    elif choice == "8":
        total = len(assistants)
        online = sum(1 for a in assistants if a.online)
        offline = total - online
        avg_score = sum(a.score for a in assistants) / total if total else 0
        print(f"\n系统统计信息：\n总助手数:{total}\n在线:{online}\n离线:{offline}\n平均能力评分:{avg_score:.2f}")

    elif choice == "0":
        print("再见！")
        break

    else:
        print("无效选择，请重新输入。")
